package com.wxh.multithread;

import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @ClassName: TestJUC
 * @Description: 测试java.util.concurrent
 * @Author wxh
 * @Date: 2022/2/17 10:19
 * @Version V1.0.0
 * @Since 1.8
 */
public class TestJUC {
    /**
     *  JUC下安全类型的集合类
     * @param args
     */
    public static void main(String[] args) {
        CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList();
        for (int i = 0; i < 10000; i++) {
            new Thread(() -> {
                list.add(Thread.currentThread().getName());
            }).start();
        }

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(list.size());
    }
}
